//! Device API. Generated with `dbus-codegen-rust -s -d org.bluez -c nonblock -m None -p /org/bluez/hci0/dev_38_F9_D3_C2_AA_C5`.

use dbus;
use dbus::arg;
use dbus::nonblock;

pub trait OrgFreedesktopDBusIntrospectable {
    fn introspect(&self) -> nonblock::MethodReply<String>;
}

impl<'a, T: nonblock::NonblockReply, C: ::std::ops::Deref<Target = T>>
    OrgFreedesktopDBusIntrospectable for nonblock::Proxy<'a, C>
{
    fn introspect(&self) -> nonblock::MethodReply<String> {
        self.method_call("org.freedesktop.DBus.Introspectable", "Introspect", ())
            .and_then(|r: (String,)| Ok(r.0))
    }
}

pub trait OrgBluezDevice1 {
    fn disconnect(&self) -> nonblock::MethodReply<()>;
    fn connect(&self) -> nonblock::MethodReply<()>;
    fn connect_profile(&self, uuid: &str) -> nonblock::MethodReply<()>;
    fn disconnect_profile(&self, uuid: &str) -> nonblock::MethodReply<()>;
    fn pair(&self) -> nonblock::MethodReply<()>;
    fn cancel_pairing(&self) -> nonblock::MethodReply<()>;
    fn address(&self) -> nonblock::MethodReply<String>;
    fn address_type(&self) -> nonblock::MethodReply<String>;
    fn name(&self) -> nonblock::MethodReply<String>;
    fn alias(&self) -> nonblock::MethodReply<String>;
    fn set_alias(&self, value: String) -> nonblock::MethodReply<()>;
    fn class(&self) -> nonblock::MethodReply<u32>;
    fn appearance(&self) -> nonblock::MethodReply<u16>;
    fn icon(&self) -> nonblock::MethodReply<String>;
    fn paired(&self) -> nonblock::MethodReply<bool>;
    fn trusted(&self) -> nonblock::MethodReply<bool>;
    fn set_trusted(&self, value: bool) -> nonblock::MethodReply<()>;
    fn blocked(&self) -> nonblock::MethodReply<bool>;
    fn set_blocked(&self, value: bool) -> nonblock::MethodReply<()>;
    fn legacy_pairing(&self) -> nonblock::MethodReply<bool>;
    fn rssi(&self) -> nonblock::MethodReply<i16>;
    fn connected(&self) -> nonblock::MethodReply<bool>;
    fn uuids(&self) -> nonblock::MethodReply<Vec<String>>;
    fn modalias(&self) -> nonblock::MethodReply<String>;
    fn adapter(&self) -> nonblock::MethodReply<dbus::Path<'static>>;
    fn manufacturer_data(
        &self,
    ) -> nonblock::MethodReply<
        ::std::collections::HashMap<u16, arg::Variant<Box<dyn arg::RefArg + 'static>>>,
    >;
    fn service_data(
        &self,
    ) -> nonblock::MethodReply<
        ::std::collections::HashMap<String, arg::Variant<Box<dyn arg::RefArg + 'static>>>,
    >;
    fn tx_power(&self) -> nonblock::MethodReply<i16>;
    fn services_resolved(&self) -> nonblock::MethodReply<bool>;
}

impl<'a, T: nonblock::NonblockReply, C: ::std::ops::Deref<Target = T>> OrgBluezDevice1
    for nonblock::Proxy<'a, C>
{
    fn disconnect(&self) -> nonblock::MethodReply<()> {
        self.method_call("org.bluez.Device1", "Disconnect", ())
    }

    fn connect(&self) -> nonblock::MethodReply<()> {
        self.method_call("org.bluez.Device1", "Connect", ())
    }

    fn connect_profile(&self, uuid: &str) -> nonblock::MethodReply<()> {
        self.method_call("org.bluez.Device1", "ConnectProfile", (uuid,))
    }

    fn disconnect_profile(&self, uuid: &str) -> nonblock::MethodReply<()> {
        self.method_call("org.bluez.Device1", "DisconnectProfile", (uuid,))
    }

    fn pair(&self) -> nonblock::MethodReply<()> {
        self.method_call("org.bluez.Device1", "Pair", ())
    }

    fn cancel_pairing(&self) -> nonblock::MethodReply<()> {
        self.method_call("org.bluez.Device1", "CancelPairing", ())
    }

    fn address(&self) -> nonblock::MethodReply<String> {
        <Self as nonblock::stdintf::org_freedesktop_dbus::Properties>::get(
            &self,
            "org.bluez.Device1",
            "Address",
        )
    }

    fn address_type(&self) -> nonblock::MethodReply<String> {
        <Self as nonblock::stdintf::org_freedesktop_dbus::Properties>::get(
            &self,
            "org.bluez.Device1",
            "AddressType",
        )
    }

    fn name(&self) -> nonblock::MethodReply<String> {
        <Self as nonblock::stdintf::org_freedesktop_dbus::Properties>::get(
            &self,
            "org.bluez.Device1",
            "Name",
        )
    }

    fn alias(&self) -> nonblock::MethodReply<String> {
        <Self as nonblock::stdintf::org_freedesktop_dbus::Properties>::get(
            &self,
            "org.bluez.Device1",
            "Alias",
        )
    }

    fn class(&self) -> nonblock::MethodReply<u32> {
        <Self as nonblock::stdintf::org_freedesktop_dbus::Properties>::get(
            &self,
            "org.bluez.Device1",
            "Class",
        )
    }

    fn appearance(&self) -> nonblock::MethodReply<u16> {
        <Self as nonblock::stdintf::org_freedesktop_dbus::Properties>::get(
            &self,
            "org.bluez.Device1",
            "Appearance",
        )
    }

    fn icon(&self) -> nonblock::MethodReply<String> {
        <Self as nonblock::stdintf::org_freedesktop_dbus::Properties>::get(
            &self,
            "org.bluez.Device1",
            "Icon",
        )
    }

    fn paired(&self) -> nonblock::MethodReply<bool> {
        <Self as nonblock::stdintf::org_freedesktop_dbus::Properties>::get(
            &self,
            "org.bluez.Device1",
            "Paired",
        )
    }

    fn trusted(&self) -> nonblock::MethodReply<bool> {
        <Self as nonblock::stdintf::org_freedesktop_dbus::Properties>::get(
            &self,
            "org.bluez.Device1",
            "Trusted",
        )
    }

    fn blocked(&self) -> nonblock::MethodReply<bool> {
        <Self as nonblock::stdintf::org_freedesktop_dbus::Properties>::get(
            &self,
            "org.bluez.Device1",
            "Blocked",
        )
    }

    fn legacy_pairing(&self) -> nonblock::MethodReply<bool> {
        <Self as nonblock::stdintf::org_freedesktop_dbus::Properties>::get(
            &self,
            "org.bluez.Device1",
            "LegacyPairing",
        )
    }

    fn rssi(&self) -> nonblock::MethodReply<i16> {
        <Self as nonblock::stdintf::org_freedesktop_dbus::Properties>::get(
            &self,
            "org.bluez.Device1",
            "RSSI",
        )
    }

    fn connected(&self) -> nonblock::MethodReply<bool> {
        <Self as nonblock::stdintf::org_freedesktop_dbus::Properties>::get(
            &self,
            "org.bluez.Device1",
            "Connected",
        )
    }

    fn uuids(&self) -> nonblock::MethodReply<Vec<String>> {
        <Self as nonblock::stdintf::org_freedesktop_dbus::Properties>::get(
            &self,
            "org.bluez.Device1",
            "UUIDs",
        )
    }

    fn modalias(&self) -> nonblock::MethodReply<String> {
        <Self as nonblock::stdintf::org_freedesktop_dbus::Properties>::get(
            &self,
            "org.bluez.Device1",
            "Modalias",
        )
    }

    fn adapter(&self) -> nonblock::MethodReply<dbus::Path<'static>> {
        <Self as nonblock::stdintf::org_freedesktop_dbus::Properties>::get(
            &self,
            "org.bluez.Device1",
            "Adapter",
        )
    }

    fn manufacturer_data(
        &self,
    ) -> nonblock::MethodReply<
        ::std::collections::HashMap<u16, arg::Variant<Box<dyn arg::RefArg + 'static>>>,
    > {
        <Self as nonblock::stdintf::org_freedesktop_dbus::Properties>::get(
            &self,
            "org.bluez.Device1",
            "ManufacturerData",
        )
    }

    fn service_data(
        &self,
    ) -> nonblock::MethodReply<
        ::std::collections::HashMap<String, arg::Variant<Box<dyn arg::RefArg + 'static>>>,
    > {
        <Self as nonblock::stdintf::org_freedesktop_dbus::Properties>::get(
            &self,
            "org.bluez.Device1",
            "ServiceData",
        )
    }

    fn tx_power(&self) -> nonblock::MethodReply<i16> {
        <Self as nonblock::stdintf::org_freedesktop_dbus::Properties>::get(
            &self,
            "org.bluez.Device1",
            "TxPower",
        )
    }

    fn services_resolved(&self) -> nonblock::MethodReply<bool> {
        <Self as nonblock::stdintf::org_freedesktop_dbus::Properties>::get(
            &self,
            "org.bluez.Device1",
            "ServicesResolved",
        )
    }

    fn set_alias(&self, value: String) -> nonblock::MethodReply<()> {
        <Self as nonblock::stdintf::org_freedesktop_dbus::Properties>::set(
            &self,
            "org.bluez.Device1",
            "Alias",
            value,
        )
    }

    fn set_trusted(&self, value: bool) -> nonblock::MethodReply<()> {
        <Self as nonblock::stdintf::org_freedesktop_dbus::Properties>::set(
            &self,
            "org.bluez.Device1",
            "Trusted",
            value,
        )
    }

    fn set_blocked(&self, value: bool) -> nonblock::MethodReply<()> {
        <Self as nonblock::stdintf::org_freedesktop_dbus::Properties>::set(
            &self,
            "org.bluez.Device1",
            "Blocked",
            value,
        )
    }
}

pub trait OrgFreedesktopDBusProperties {
    fn get(
        &self,
        interface: &str,
        name: &str,
    ) -> nonblock::MethodReply<arg::Variant<Box<dyn arg::RefArg + 'static>>>;
    fn set(
        &self,
        interface: &str,
        name: &str,
        value: arg::Variant<Box<dyn arg::RefArg>>,
    ) -> nonblock::MethodReply<()>;
    fn get_all(
        &self,
        interface: &str,
    ) -> nonblock::MethodReply<
        ::std::collections::HashMap<String, arg::Variant<Box<dyn arg::RefArg + 'static>>>,
    >;
}

impl<'a, T: nonblock::NonblockReply, C: ::std::ops::Deref<Target = T>> OrgFreedesktopDBusProperties
    for nonblock::Proxy<'a, C>
{
    fn get(
        &self,
        interface: &str,
        name: &str,
    ) -> nonblock::MethodReply<arg::Variant<Box<dyn arg::RefArg + 'static>>> {
        self.method_call("org.freedesktop.DBus.Properties", "Get", (interface, name))
            .and_then(|r: (arg::Variant<Box<dyn arg::RefArg + 'static>>,)| Ok(r.0))
    }

    fn set(
        &self,
        interface: &str,
        name: &str,
        value: arg::Variant<Box<dyn arg::RefArg>>,
    ) -> nonblock::MethodReply<()> {
        self.method_call(
            "org.freedesktop.DBus.Properties",
            "Set",
            (interface, name, value),
        )
    }

    fn get_all(
        &self,
        interface: &str,
    ) -> nonblock::MethodReply<
        ::std::collections::HashMap<String, arg::Variant<Box<dyn arg::RefArg + 'static>>>,
    > {
        self.method_call("org.freedesktop.DBus.Properties", "GetAll", (interface,))
            .and_then(
                |r: (
                    ::std::collections::HashMap<
                        String,
                        arg::Variant<Box<dyn arg::RefArg + 'static>>,
                    >,
                )| Ok(r.0),
            )
    }
}

#[derive(Debug)]
pub struct OrgFreedesktopDBusPropertiesPropertiesChanged {
    pub interface: String,
    pub changed_properties:
        ::std::collections::HashMap<String, arg::Variant<Box<dyn arg::RefArg + 'static>>>,
    pub invalidated_properties: Vec<String>,
}

impl arg::AppendAll for OrgFreedesktopDBusPropertiesPropertiesChanged {
    fn append(&self, i: &mut arg::IterAppend) {
        arg::RefArg::append(&self.interface, i);
        arg::RefArg::append(&self.changed_properties, i);
        arg::RefArg::append(&self.invalidated_properties, i);
    }
}

impl arg::ReadAll for OrgFreedesktopDBusPropertiesPropertiesChanged {
    fn read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError> {
        Ok(OrgFreedesktopDBusPropertiesPropertiesChanged {
            interface: i.read()?,
            changed_properties: i.read()?,
            invalidated_properties: i.read()?,
        })
    }
}

impl dbus::message::SignalArgs for OrgFreedesktopDBusPropertiesPropertiesChanged {
    const NAME: &'static str = "PropertiesChanged";
    const INTERFACE: &'static str = "org.freedesktop.DBus.Properties";
}
